package com.neuedu.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neuedu.common.ResultJson;
import com.neuedu.entity.Department;
import com.neuedu.service.DepartmentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 科室表 前端控制器
 * </p>
 *
 * @author LiYang
 * @since 2024-11-05
 */
@RestController
@RequestMapping("/department")
//@CrossOrigin(origins = "http://127.0.0.1:81") //解决跨域，明确前端请求地址
public class DepartmentController {
    @Resource
    DepartmentService departmentService;
    @GetMapping("/list")
    ResultJson<IPage<Department>> list(Integer pageNo, Integer pageSize,String name)throws InterruptedException{
        return ResultJson.success(departmentService.list(pageNo, pageSize, name));
    }
    @PostMapping("/add")
    ResultJson<Boolean> add(String code, String name, String type) {
        return ResultJson.success(departmentService.add(code, name, type), "添加科室成功");
    }
    @GetMapping("/check")
    ResultJson<Boolean> check(String field, String value,Long id) {
        return ResultJson.success(departmentService.check(field, value, id));
    }
    @PostMapping("/del")
    ResultJson<Boolean> del(Long id, Boolean delmark) {
        return ResultJson.success(departmentService.del(id, delmark), delmark ? "还原科室成功" : "删除科室成功");
    }
    @GetMapping("/getById")
    ResultJson<Department> getById(Long id) {
        return ResultJson.success(departmentService.getById(id));
    }
    @PostMapping("/update")
    ResultJson<Boolean> update(Long id,String code, String name, String type) {
        return ResultJson.success(departmentService.update(id, code, name, type), "修改科室成功");
    }

    /**
     * 获取可挂号科室
     * @return
     */
    @GetMapping("/getRegisterDept")
    List<Department> getRegisterDept() {
        return departmentService.getRegisterDept();
    }
}
